#define _CRT_SECURE_NO_WARNINGS 1


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur1 = 0;
    int cur0 = 0;
    for (int i = 0;i < n;i++)
    {
        if (s[i] - '0')
            cur1++;
        else
            cur0++;
    }
    if (cur1 * cur0 == 0)
        cout << 0;
    else if (cur1 != cur0)
        cout << 1;
    else if (n % 2 == 0 && n > 2)
        cout << 2;
    else
        cout << -1;
    return 0;
}